(function (a) {
    var g = function (c, b, d) {
        a("#J_ConfirmD")[0] && a("#J_ConfirmD").remove();
        a("body").append('<div id="J_ConfirmD" class="g-dialog tip-dialog"><div class="dialog-content"><div class="hd"><h3>\u63d0\u793a</h3></div><div class="bd clearfix">' + ('<p class="pt10 tac">' + c + "</p>") + '<div class="act-row"><p class="inlineblock"><a class="bbl-btn mr10" id="J_Confirm" href="javascript:;">\u786e\u5b9a</a><a class="bgr-btn" id="J_Cancel" href="javascript:;">\u53d6\u6d88</a></p></div></div><a class="close" href="javascript:;"></a></div></div>');
        a("#J_ConfirmD").overlay({top:"center", mask:{color:"#000", loadSpeed:200, opacity:0.3}, closeOnClick:!0, load:!0, onClose:function () {
            d();
            a("#commentDialog,#exposeMask").remove()
        }});
        a("#J_Cancel").unbind("click").click(function () {
            a("#J_ConfirmD").overlay().close()
        });
        a("#J_Confirm").unbind("click").click(function () {
            a("#J_ConfirmD").overlay().close();
            b()
        })
    };
    a("a[rel=follow]").live("click", function () {
        a.guang.dialog.isLogin() && "false" != a(this).data("enable") && (a(this).data("enable", "false"), $this = a(this), a.ajax({url:GUANGER.path +
            "/addFollow", type:"post", dataType:"json", data:{tuserId:a(this).data("userid")}, jQueryDom:$this, success:function (c) {
            switch (c.code) {
                case 100:
                    this.jQueryDom.data("enable", "true");
                    a.guang.addFollowCallback(c, this.jQueryDom);
                    break;
                case 101:
                    $this.data("enable", "true");
                    a.guang.tip.conf.tipClass = "tipmodal tipmodal-error2";
                    a.guang.tip.show($this, "\u53c2\u6570\u9519\u8bef");
                    break;
                case 103:
                    $this.data("enable", "true");
                    a.guang.tip.conf.tipClass = "tipmodal tipmodal-error2";
                    a.guang.tip.show($this, "\u91cd\u590d\u5173\u6ce8\u4e86\u4f60\u7684\u670b\u53cb\uff01");
                    break;
                case 111:
                    $this.data("enable", "true");
                    a.guang.tip.conf.tipClass = "tipmodal tipmodal-error2";
                    a.guang.tip.show($this, "\u62b1\u6b49\uff0c\u4f60\u7684\u5173\u6ce8\u5df2\u8fbe\u4e0a\u9650\u3002");
                    break;
                case 300:
                    a.guang.dialog.login();
                    break;
                case 446:
                    a.guang.tip.conf.tipClass = "tipmodal tipmodal-error2", a.guang.tip.show($this, "\u4f60\u5df2\u88ab\u7981\u6b62\u5173\u6ce8\u597d\u53cb\uff01")
            }
        }}))
    });
    a.guang.removeFansCallback = function (a) {
        a.parents(".section").remove()
    };
    a("a[rel=removefans]").live("click",
        function () {
            if (a.guang.dialog.isLogin() && "false" != a(this).data("enable")) {
                a(this).data("enable", "false");
                $this = a(this);
                var c = "\u786e\u5b9a\u8981\u79fb\u9664\u7c89\u4e1d\u201c" + $this.data("usernick") + "\u201d\uff1f";
                g(c, function () {
                    a.ajax({url:GUANGER.path + "/removeFans", type:"post", dataType:"json", data:{tuserId:$this.data("userid")}, success:function (b) {
                        switch (b.code) {
                            case 100:
                                $this.data("enable", "true");
                                a.guang.removeFansCallback($this, b);
                                break;
                            case 101:
                                $this.data("enable", "true");
                                a.guang.tip.conf.tipClass =
                                    "tipmodal tipmodal-error2";
                                a.guang.tip.show($this, b.msg);
                                break;
                            case 300:
                                a.guang.dialog.login()
                        }
                    }})
                }, function () {
                    $this.data("enable", "true")
                })
            }
        });
    a.guang.removeFollowCallback = function () {
        o.parents(".section").remove()
    };
    a("a[rel=removefollow]").live("click", function () {
        if (a.guang.dialog.isLogin() && "false" != a(this).data("enable")) {
            a(this).data("enable", "false");
            var c = a(this), b = "\u786e\u5b9a\u4e0d\u518d\u5173\u6ce8\u201c" + c.data("usernick") + "\u201d\uff1f";
            g(b, function () {
                a.ajax({url:GUANGER.path + "/removeFollow",
                    type:"post", dataType:"json", data:{tuserId:c.data("userid")}, success:function (b) {
                        switch (b.code) {
                            case 100:
                                c.data("enable", "true");
                                a.guang.removeFollowCallback(b, c);
                                break;
                            case 101:
                                c.data("enable", "true");
                                a.guang.tip.conf.tipClass = "tipmodal tipmodal-error2";
                                a.guang.tip.show(c, "\u53c2\u6570\u9519\u8bef");
                                break;
                            case 300:
                                a.guang.dialog.login()
                        }
                    }})
            }, function () {
                c.data("enable", "true")
            })
        }
    });
    a.guang.addFollowCallback = function (c, b) {
        "0" == b.attr("data-followtype") && (c.isYouFollowed ? b.after("<div class='followed-btn-big'>\u4e92\u76f8\u5173\u6ce8<span class='mr5 ml5'>|</span><a rel='removefollow' data-followtype='0' data-usernick=" +
            b.data("usernick") + " data-userid='" + b.data("userid") + "' href='javascript:;'>\u53d6\u6d88</a></div>") : b.after("<div class='followed-btn-big'>\u5df2\u5173\u6ce8<span class='mr5 ml5'>|</span><a rel='removefollow' data-followtype='0' data-usernick=" + b.data("usernick") + " data-userid='" + b.data("userid") + "' href='javascript:;'>\u53d6\u6d88</a></div>"), b.remove());
        "1" == b.attr("data-followtype") && (b.after("<div class='followed-btn'>\u4e92\u76f8\u5173\u6ce8<span class='mr5 ml5'>|</span><a rel='removefollow' data-followtype='1' data-usernick=" +
            b.data("usernick") + " data-userid='" + b.data("userid") + "' href='javascript:;'>\u53d6\u6d88</a></div>"), b.remove());
        "4" == b.attr("data-followtype") && (c.isYouFollowed ? b.after("<div class='followed-btn'>\u4e92\u76f8\u5173\u6ce8</div>") : b.after("<div class='followed-btn'>\u5df2\u5173\u6ce8</div>"), b.remove());
        "5" == b.attr("data-followtype") && (c.isYouFollowed ? b.after("<div class='followed-btn'>\u4e92\u76f8\u5173\u6ce8<span class='mr5 ml5'>|</span><a rel='removefollow' data-followtype='5' data-usernick=" + b.data("usernick") +
            " data-userid='" + b.data("userid") + "' href='javascript:;'>\u53d6\u6d88</a></div>") : b.after("<div class='followed-btn'>\u5df2\u5173\u6ce8<span class='mr5 ml5'>|</span><a rel='removefollow' data-followtype='5' data-usernick=" + b.data("usernick") + " data-userid='" + b.data("userid") + "' href='javascript:;'>\u53d6\u6d88</a></div>"), b.remove());
        if ("3" == b.attr("data-followtype")) {
            for (var d = b.parents("li").siblings(), e = "", f = 0; f < d.length; f++)e += e.length ? "," + d.eq(f).find("a[rel=follow]").attr("data-userid") : d.eq(f).find("a[rel=follow]").attr("data-userid");
            a.ajax({url:GUANGER.path + "/u/getUserInterested.html", type:"post", dataType:"json", data:{tuserIds:e}, success:function (a) {
                switch (a.code) {
                    case 100:
                        if (a.snsFriend) {
                            a = a.snsFriend;
                            if (!a.userPhoto || a.userPhoto.length == 0)a.userPhoto = "http://static.guang.com/images/user/photo/avatar-50.png";
                            a = '<li><div class="user-pic"><a href="' + GUANGER.path + "/u/" + a.userId + '" title="' + a.userNick + '"><img src="' + a.userPhoto + '" width="50" height="50" alt="' + a.userNick + '" title="' + a.userNick + '"/></a></div><div class="user-info"><p class="username"><a href="' +
                                GUANGER.path + "/u/" + a.userId + '" title="' + a.userNick + '">' + a.userNick + "</a></p><p>" + a.description + '</p><a rel="follow" href="javascript:;" class="follow-btn" data-followtype="3" data-userid="' + a.tuser + '">\u52a0\u5173\u6ce8</a></div></li>';
                            b.parents("li").after(a)
                        }
                        b.parents("li").remove();
                        break;
                    case 101:
                        b.parents("li").remove()
                }
            }})
        }
        if ("6" == b.attr("data-followtype")) {
            d = b.parents("dl").siblings("dl");
            e = "";
            for (f = 0; f < d.length; f++)e += e.length ? "," + d.eq(f).find("a[rel=follow]").attr("data-userid") : d.eq(f).find("a[rel=follow]").attr("data-userid");
            a.ajax({url:GUANGER.path + "/u/getUserInterested.html", type:"post", dataType:"json", data:{tuserIds:e}, success:function (a) {
                switch (a.code) {
                    case 100:
                        if (a.snsFriend) {
                            a = a.snsFriend;
                            if (!a.userPhoto || a.userPhoto.length == 0)a.userPhoto = "http://static.guang.com/images/user/photo/avatar-50.png";
                            a = '<dl class="gper clearfix"><dt><a href="' + GUANGER.path + "/u/" + a.userId + '" title="' + a.userNick + '" target="_blank"><img src="' + a.userPhoto + '" width="50" height="50" alt="' + a.userNick + '" /></a></dt><dd><a class="name" href="' +
                                GUANGER.path + "/u/" + a.userId + '" target="_blank">' + a.userNick + '</a><p class="from">' + a.description + '</p><a rel="follow" href="javascript:;" class="follow-btn" data-followtype="6" data-userid="' + a.tuser + '">\u52a0\u5173\u6ce8</a></dd></dl>';
                            b.parents("dl").after(a)
                        }
                        b.parents("dl").remove();
                        break;
                    case 101:
                        b.parents("dl").remove()
                }
            }})
        }
    };
    a.guang.removeFollowCallback = function (a, b) {
        "0" == b.attr("data-followtype") && (b.parent().after("<a rel='follow' href='javascript:;' class='follow-btn-big' data-followtype='0' data-usernick=" +
            b.data("usernick") + " data-userid=" + b.data("userid") + ">\u52a0\u5173\u6ce8</a>"), b.parent().remove());
        "1" == b.attr("data-followtype") && (b.parent().after("<a rel='follow' href='javascript:;' class='follow-btn' data-followtype='1' data-usernick=" + b.data("usernick") + " data-userid=" + b.data("userid") + ">\u52a0\u5173\u6ce8</a>"), b.parent().remove());
        "5" == b.attr("data-followtype") && (b.parent().after("<a rel='follow' href='javascript:;' class='follow-btn' data-followtype='5' data-usernick=" + b.data("usernick") +
            " data-userid=" + b.data("userid") + ">\u52a0\u5173\u6ce8</a>"), b.parent().remove());
        "2" == b.attr("data-followtype") && b.parents(".section").remove()
    }
})(jQuery);
